home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 123 / vcsrc / gram.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-05-10  |  12.0 KB  |  441 lines

  1. # line 15 "gram.y"
  2. #include "sc.h"
  3.  
  4. # line 18 "gram.y"
  5. typedef union  {
  6.     int ival;
  7.     double fval;
  8.     struct ent *ent;
  9.     struct enode *enode;
  10.     char *sval;
  11. } YYSTYPE;
  12. # define STRING 257
  13. # define NUMBER 258
  14. # define FNUMBER 259
  15. # define WORD 260
  16. # define COL 261
  17. # define S_FORMAT 262
  18. # define S_LABEL 263
  19. # define S_LEFTSTRING 264
  20. # define S_RIGHTSTRING 265
  21. # define S_GET 266
  22. # define S_PUT 267
  23. # define S_MERGE 268
  24. # define S_LET 269
  25. # define S_WRITE 270
  26. # define S_TBL 271
  27. # define S_PROGLET 272
  28. # define S_COPY 273
  29. # define S_SHOW 274
  30. # define K_FIXED 275
  31. # define K_SUM 276
  32. # define K_PROD 277
  33. # define K_AVE 278
  34. #define yyclearin yychar = -1
  35. #define yyerrok yyerrflag = 0
  36. extern int yychar;
  37. extern short yyerrflag;
  38. #ifndef YYMAXDEPTH
  39. #define YYMAXDEPTH 150
  40. #endif
  41. YYSTYPE yylval, yyval;
  42. # define YYERRCODE 256
  43. short yyexca[] ={
  44. -1, 1,
  45.     0, -1,
  46.     -2, 0,
  47. -1, 83,
  48.     60, 0,
  49.     61, 0,
  50.     62, 0,
  51.     -2, 34,
  52. -1, 85,
  53.     60, 0,
  54.     61, 0,
  55.     62, 0,
  56.     -2, 35,
  57. -1, 86,
  58.     60, 0,
  59.     61, 0,
  60.     62, 0,
  61.     -2, 36,
  62. -1, 96,
  63.     60, 0,
  64.     61, 0,
  65.     62, 0,
  66.     -2, 39,
  67. -1, 97,
  68.     60, 0,
  69.     61, 0,
  70.     62, 0,
  71.     -2, 41,
  72. -1, 98,
  73.     60, 0,
  74.     61, 0,
  75.     62, 0,
  76.     -2, 40,
  77.     };
  78. # define YYNPROD 43
  79. # define YYLAST 267
  80. short yyact[]={
  81.  
  82.   14,  69,  70,  71,  16,  55,   6,   3,   4,   5,
  83.    7,   9,   8,   2,  10,  11,  49,  13,  12,  27,
  84.   49,  54,  26,  43,  49,  20,  44,  43,  45,  53,
  85.   44,  43,  45,  34,  44,  30,  45,  52,  51,  50,
  86.   25,  24,  23,  22,  87,  21,  90,  42,  84,  67,
  87.   33,  42, 105,  32,  65,  42,  31,  67,  59,  57,
  88.   29,  58,  65,  60, 104,  94,  59,  57, 103,  58,
  89.   56,  60,  36,  35,  95, 111,  62,  63,  64,  61,
  90.  110, 109,  93,  67,  62,  63,  64,  61,  65,  39,
  91.   67,  67,  59,  57,  92,  58,  65,  60,  38,  59,
  92.   59,  57,  91,  58,  60,  60,  67,   1,   0,  48,
  93.   62,  63,  64,  48,   0,   0,   0,  48,  62,  63,
  94.   64,  61,  40,   0,   0,  15,  17,  18,  19,   0,
  95.    0,  68,   0,   0,  73,  74,  28,   0,  75,  76,
  96.   66,   0,  72,   0,   0,   0,   0,   0,  66,   0,
  97.    0,  37,   0,   0,   0,   0,  78,  79,  80,  81,
  98.   82,  83,  85,  86,  88,  89,  67,   0,   0,   0,
  99.    0,   0,   0,   0,  66,  59,  57,   0,  58,  77,
  100.   60,   0,  66,  96,   0,   0,  97,   0,   0,  98,
  101.   67,   0,   0,   0, 102,  65,  67,   0,   0,  59,
  102.   57,   0,  58,   0,  60,  59,  57,   0,  58,   0,
  103.   60,   0,   0,   0,  99, 100, 101,  62,  63,  64,
  104.    0,   0,   0,  62,  63,  64, 106, 107, 108,   0,
  105.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  106.    0,  46,  47,   0,  16,  46,  47,   0,  16,  46,
  107.   47,   0,  16,   0,   0,   0,   0,   0,  41,   0,
  108.    0,   0,  41,   0,   0,   0,  41 };
  109. short yypact[]={
  110.  
  111. -256,-1000,-257,-257,-257,-257,-236,-212,-214,-215,
  112. -216,-217,-239,-257,-1000,  -1,-223,  -5,  -8, -11,
  113. -225,-1000,-1000,-1000,-1000,-1000,  15,  14,-257,  -9,
  114. -1000,-218,-219,-220,-229,-240,-253,  12,  58,-1000,
  115. -1000,  -9,-275,  -9,  -9,  -9,-1000,-1000,  -9,  -9,
  116. -1000,-1000,-1000,-1000,-1000,-1000,-257,  -9,  -9,  -9,
  117.   -9,  -9, -13,  -9, -17,  -9,  -9, -15,-1000,  62,
  118.   54,  42,  24,-1000,-1000,-1000,-1000,-1000,  57,  57,
  119.   73,  73,  16, 133,  -9, 133, 133,  -9, 163, 157,
  120.   -9,-257,-257,-257,-1000,  -9, 133, 133, 133,  10,
  121.    6,  -6,  50,-257,-257,-257,  40,  39,  34,-1000,
  122. -1000,-1000 };
  123. short yypgo[]={
  124.  
  125.    0, 122,  98,  89, 107 };
  126. short yyr1[]={
  127.  
  128.    0,   4,   4,   4,   4,   4,   4,   4,   4,   4,
  129.    4,   4,   4,   4,   4,   4,   3,   3,   3,   3,
  130.    3,   3,   3,   3,   3,   3,   3,   3,   2,   2,
  131.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  132.    2,   2,   1 };
  133. short yyr2[]={
  134.  
  135.    0,   4,   4,   4,   4,   4,   2,   2,   2,   2,
  136.    2,   4,   4,   5,   0,   1,   1,   2,   7,   7,
  137.    7,   3,   2,   2,   1,   1,   2,   2,   3,   3,
  138.    3,   3,   1,   5,   3,   3,   3,   3,   3,   4,
  139.    4,   4,   2 };
  140. short yychk[]={
  141.  
  142. -1000,  -4, 269, 263, 264, 265, 262, 266, 268, 267,
  143.  270, 271, 274, 273, 256,  -1, 261,  -1,  -1,  -1,
  144.  261, 257, 257, 257, 257, 257, 261, 258,  -1,  61,
  145.  258,  61,  61,  61, 258,  58,  58,  -1,  -2,  -3,
  146.   -1, 275,  64,  40,  43,  45, 258, 259, 126,  33,
  147.  257, 257, 257, 258, 261, 258,  58,  43,  45,  42,
  148.   47,  63,  60,  61,  62,  38, 124,  33,  -3, 276,
  149.  277, 278,  -2,  -3,  -3,  -3,  -3,  -1,  -2,  -2,
  150.   -2,  -2,  -2,  -2,  61,  -2,  -2,  61,  -2,  -2,
  151.   61,  40,  40,  40,  41,  58,  -2,  -2,  -2,  -1,
  152.   -1,  -1,  -2,  58,  58,  58,  -1,  -1,  -1,  41,
  153.   41,  41 };
  154. short yydef[]={
  155.  
  156.   14,  -2,   0,   0,   0,   0,   0,   0,   0,   0,
  157.    0,   0,   0,   0,  15,   0,   0,   0,   0,   0,
  158.    0,   6,   7,   8,   9,  10,   0,   0,   0,   0,
  159.   42,   0,   0,   0,   0,   0,   0,   0,   1,  32,
  160.   16,   0,   0,   0,   0,   0,  24,  25,   0,   0,
  161.    2,   3,   4,   5,  11,  12,   0,   0,   0,   0,
  162.    0,   0,   0,   0,   0,   0,   0,   0,  17,   0,
  163.    0,   0,   0,  22,  23,  26,  27,  13,  28,  29,
  164.   30,  31,   0,  -2,   0,  -2,  -2,   0,  37,  38,
  165.    0,   0,   0,   0,  21,   0,  -2,  -2,  -2,   0,
  166.    0,   0,  33,   0,   0,   0,   0,   0,   0,  18,
  167.   19,  20 };
  168. #ifndef lint
  169. static char yaccpar_sccsid[] = "@(#)yaccpar    4.1    (Berkeley)    2/11/83";
  170. #endif not lint
  171.  
  172. #
  173. # define YYFLAG -1000
  174. # define YYERROR goto yyerrlab
  175. # define YYACCEPT return(0)
  176. # define YYABORT return(1)
  177.  
  178. /*    parser for yacc output    */
  179.  
  180. #ifdef YYDEBUG
  181. int yydebug = 0; /* 1 for debugging */
  182. #endif
  183. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  184. int yychar = -1; /* current input token number */
  185. int yynerrs = 0;  /* number of errors */
  186. short yyerrflag = 0;  /* error recovery flag */
  187.  
  188. yyparse() {
  189.  
  190.     short yys[YYMAXDEPTH];
  191.     short yyj, yym;
  192.     register YYSTYPE *yypvt;
  193.     register short yystate, *yyps, yyn;
  194.     register YYSTYPE *yypv;
  195.     register short *yyxi;
  196.  
  197.     yystate = 0;
  198.     yychar = -1;
  199.     yynerrs = 0;
  200.     yyerrflag = 0;
  201.     yyps= &yys[-1];
  202.     yypv= &yyv[-1];
  203.  
  204.  yystack:    /* put a state and value onto the stack */
  205.  
  206. #ifdef YYDEBUG
  207.     if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
  208. #endif
  209.         if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
  210.         *yyps = yystate;
  211.         ++yypv;
  212.         *yypv = yyval;
  213.  
  214.  yynewstate:
  215.  
  216.     yyn = yypact[yystate];
  217.  
  218.     if( yyn<= YYFLAG ) goto yydefault; /* simple state */
  219.  
  220.     if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
  221.     if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
  222.  
  223.     if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
  224.         yychar = -1;
  225.         yyval = yylval;
  226.         yystate = yyn;
  227.         if( yyerrflag > 0 ) --yyerrflag;
  228.         goto yystack;
  229.         }
  230.  
  231.  yydefault:
  232.     /* default state action */
  233.  
  234.     if( (yyn=yydef[yystate]) == -2 ) {
  235.         if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
  236.         /* look through exception table */
  237.  
  238.         for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
  239.  
  240.         while( *(yyxi+=2) >= 0 ){
  241.             if( *yyxi == yychar ) break;
  242.             }
  243.         if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
  244.         }
  245.  
  246.     if( yyn == 0 ){ /* error */
  247.         /* error ... attempt to resume parsing */
  248.  
  249.         switch( yyerrflag ){
  250.  
  251.         case 0:   /* brand new error */
  252.  
  253.             yyerror( "syntax error" );
  254.         yyerrlab:
  255.             ++yynerrs;
  256.  
  257.         case 1:
  258.         case 2: /* incompletely recovered error ... try again */
  259.  
  260.             yyerrflag = 3;
  261.  
  262.             /* find a state where "error" is a legal shift action */
  263.  
  264.             while ( yyps >= yys ) {
  265.                yyn = yypact[*yyps] + YYERRCODE;
  266.                if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
  267.                   yystate = yyact[yyn];  /* simulate a shift of "error" */
  268.                   goto yystack;
  269.                   }
  270.                yyn = yypact[*yyps];
  271.  
  272.                /* the current yyps has no shift onn "error", pop stack */
  273.  
  274. #ifdef YYDEBUG
  275.                if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
  276. #endif
  277.                --yyps;
  278.                --yypv;
  279.                }
  280.  
  281.             /* there is no state on the stack with an error shift ... abort */
  282.  
  283.     yyabort:
  284.             return(1);
  285.  
  286.  
  287.         case 3:  /* no shift yet; clobber input char */
  288.  
  289. #ifdef YYDEBUG
  290.             if( yydebug ) printf( "error recovery discards char %d\n", yychar );
  291. #endif
  292.  
  293.             if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  294.             yychar = -1;
  295.             goto yynewstate;   /* try again in the same state */
  296.  
  297.             }
  298.  
  299.         }
  300.  
  301.     /* reduction by production yyn */
  302.  
  303. #ifdef YYDEBUG
  304.         if( yydebug ) printf("reduce %d\n",yyn);
  305. #endif
  306.         yyps -= yyr2[yyn];
  307.         yypvt = yypv;
  308.         yypv -= yyr2[yyn];
  309.         yyval = yypv[1];
  310.         yym=yyn;
  311.             /* consult goto table to find next state */
  312.         yyn = yyr1[yyn];
  313.         yyj = yypgo[yyn] + *yyps + 1;
  314.         if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  315.         switch(yym){
  316.             
  317. case 1:
  318. # line 59 "gram.y"
  319. { let (yypvt[-2].ent, yypvt[-0].enode); } break;
  320. case 2:
  321. # line 61 "gram.y"
  322. { label (yypvt[-2].ent, yypvt[-0].sval, 0); } break;
  323. case 3:
  324. # line 63 "gram.y"
  325. { label (yypvt[-2].ent, yypvt[-0].sval, -1); } break;
  326. case 4:
  327. # line 65 "gram.y"
  328. { label (yypvt[-2].ent, yypvt[-0].sval, 1); } break;
  329. case 5:
  330. # line 67 "gram.y"
  331. { fwidth[yypvt[-2].ival] = yypvt[-1].ival;
  332.                   FullUpdate++;
  333.                   modflg++;
  334.                   precision[yypvt[-2].ival] = yypvt[-0].ival; } break;
  335. case 6:
  336. # line 71 "gram.y"
  337. { readfile (yypvt[-0].sval,1); } break;
  338. case 7:
  339. # line 72 "gram.y"
  340. { readfile (yypvt[-0].sval,0); } break;
  341. case 8:
  342. # line 73 "gram.y"
  343. { writefile (yypvt[-0].sval); } break;
  344. case 9:
  345. # line 74 "gram.y"
  346. { printfile (yypvt[-0].sval); } break;
  347. case 10:
  348. # line 75 "gram.y"
  349. { tblprintfile (yypvt[-0].sval); } break;
  350. case 11:
  351. # line 76 "gram.y"
  352. { showcol( yypvt[-2].ival, yypvt[-0].ival); } break;
  353. case 12:
  354. # line 77 "gram.y"
  355. { showrow( yypvt[-2].ival, yypvt[-0].ival); } break;
  356. case 13:
  357. # line 79 "gram.y"
  358. { copy(yypvt[-3].ent, yypvt[-2].ent, yypvt[-0].ent); } break;
  359. case 16:
  360. # line 83 "gram.y"
  361. { yyval.enode = new ('v', yypvt[-0].ent); } break;
  362. case 17:
  363. # line 84 "gram.y"
  364. { yyval.enode = new ('f', 0L, yypvt[-0].enode); } break;
  365. case 18:
  366. # line 86 "gram.y"
  367. { yyval.enode = new (O_REDUCE('+'), yypvt[-3].ent, yypvt[-1].ent); } break;
  368. case 19:
  369. # line 88 "gram.y"
  370. { yyval.enode = new (O_REDUCE('*'), yypvt[-3].ent, yypvt[-1].ent); } break;
  371. case 20:
  372. # line 90 "gram.y"
  373. { yyval.enode = new (O_REDUCE('a'), yypvt[-3].ent, yypvt[-1].ent); } break;
  374. case 21:
  375. # line 91 "gram.y"
  376. { yyval.enode = yypvt[-1].enode; } break;
  377. case 22:
  378. # line 92 "gram.y"
  379. { yyval.enode = yypvt[-0].enode; } break;
  380. case 23:
  381. # line 93 "gram.y"
  382. { yyval.enode = new ('m', 0L, yypvt[-0].enode); } break;
  383. case 24:
  384. # line 94 "gram.y"
  385. { yyval.enode = new ('k', (double) yypvt[-0].ival); } break;
  386. case 25:
  387. # line 95 "gram.y"
  388. { yyval.enode = new ('k', yypvt[-0].fval); } break;
  389. case 26:
  390. # line 96 "gram.y"
  391. { yyval.enode = new ('~', 0L, yypvt[-0].enode); } break;
  392. case 27:
  393. # line 97 "gram.y"
  394. { yyval.enode = new ('~', 0L, yypvt[-0].enode); } break;
  395. case 28:
  396. # line 100 "gram.y"
  397. { yyval.enode = new ('+', yypvt[-2].enode, yypvt[-0].enode); } break;
  398. case 29:
  399. # line 101 "gram.y"
  400. { yyval.enode = new ('-', yypvt[-2].enode, yypvt[-0].enode); } break;
  401. case 30:
  402. # line 102 "gram.y"
  403. { yyval.enode = new ('*', yypvt[-2].enode, yypvt[-0].enode); } break;
  404. case 31:
  405. # line 103 "gram.y"
  406. { yyval.enode = new ('/', yypvt[-2].enode, yypvt[-0].enode); } break;
  407. case 33:
  408. # line 105 "gram.y"
  409. { yyval.enode = new ('?', yypvt[-4].enode, new(':', yypvt[-2].enode, yypvt[-0].enode)); } break;
  410. case 34:
  411. # line 106 "gram.y"
  412. { yyval.enode = new ('<', yypvt[-2].enode, yypvt[-0].enode); } break;
  413. case 35:
  414. # line 107 "gram.y"
  415. { yyval.enode = new ('=', yypvt[-2].enode, yypvt[-0].enode); } break;
  416. case 36:
  417. # line 108 "gram.y"
  418. { yyval.enode = new ('>', yypvt[-2].enode, yypvt[-0].enode); } break;
  419. case 37:
  420. # line 109 "gram.y"
  421. { yyval.enode = new ('&', yypvt[-2].enode, yypvt[-0].enode); } break;
  422. case 38:
  423. # line 110 "gram.y"
  424. { yyval.enode = new ('|', yypvt[-2].enode, yypvt[-0].enode); } break;
  425. case 39:
  426. # line 111 "gram.y"
  427. { yyval.enode = new ('~', 0L, new ('>', yypvt[-3].enode, yypvt[-0].enode)); } break;
  428. case 40:
  429. # line 112 "gram.y"
  430. { yyval.enode = new ('~', 0L, new ('=', yypvt[-3].enode, yypvt[-0].enode)); } break;
  431. case 41:
  432. # line 113 "gram.y"
  433. { yyval.enode = new ('~', 0L, new ('<', yypvt[-3].enode, yypvt[-0].enode)); } break;
  434. case 42:
  435. # line 116 "gram.y"
  436. { yyval.ent = lookat(yypvt[-0].ival , yypvt[-1].ival); } break; 
  437.         }
  438.         goto yystack;  /* stack new state and value */
  439.  
  440.     }
  441.